// Decompiled by DJ v3.5.5.77 Copyright 2003 Atanas Neshkov  Date: 16.03.2004 16:25:22
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3)
// Source File Name:   LCMail.java

package com.tizona.system;

import com.tizona.dao.jdbc.SQLRequest;

import java.io.OutputStream;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Date;

// Referenced classes of package com.tizona.system:
//            SQLRequest, Const

public class LCMail
{

    LCMail(SQLRequest sqlrequest)
    {
        sql = sqlrequest;
    }

    public void mail(String s, String s1, String s2, String s3)
        throws Exception
    {
        ResultSet resultset = sql.query("select VALUE from LC_PROPS where LC_Num=" + s + " and NAME='E-mails'");
        String s4 = "";
        String s5 = "";
        String s6 = "billing";
        String s7 = "";
        if(resultset.next())
        {
            s4 = resultset.getString(1);
            if(s4 == null)
                s4 = "";
        }
        if(s4.compareTo("") == 0)
        {
            resultset = sql.query("select VALUE from CONF_STR where NAME='EMAIL_DOMAIN'");
            if(resultset.next())
            {
                s5 = resultset.getString(1);
                if(s5 == null)
                    s5 = "";
            }
            if(s5.compareTo("") == 0)
                throw new Exception(" \356\305 \332\301\304\301\316\331 \301\304\322\305\323\301 \320\317\314\325\336\301\324\305\314\305\312 \323\317\317\302\333\305\316\311\321 ");
            for(resultset = sql.query("select LOGIN from SE where DELETED=0 and SE.LC_Num=" + s + " and SE.SVC_ID=" + 101); resultset.next();)
            {
                if(s4.compareTo("") != 0)
                    s4 = s4 + " ";
                s4 = s4 + resultset.getString(1) + "@" + s5;
            }

        }
        resultset = sql.query("select VALUE from CONF_STR where NAME='EMAIL_FROM'");
        if(resultset.next())
        {
            s6 = resultset.getString(1);
            if(s6 == null)
                s6 = "billing";
        }
        resultset = sql.query("select VALUE from CONF_STR where NAME='EMAIL_REPLY'");
        if(resultset.next())
        {
            s7 = resultset.getString(1);
            if(s7 == null)
                s7 = "";
        }
        if(s7.compareTo("") != 0)
            s7 = "<" + s7 + ">";
        if(s4.compareTo("") != 0)
        {
            Date date = new Date();
            SimpleDateFormat simpledateformat = new SimpleDateFormat();
            String s8 = Const.SENDMAIL_PATH + " " + s4;
            String s9 = "To: " + s4 + "\nFrom: \"" + s6 + "\"" + s7 + "\n" + "Subject:" + s1 + "\nDate:" + simpledateformat.format(date) + "\n" + s3 + "\n";
            s9 = s9 + s2 + "\n.\n";
            Process process = Runtime.getRuntime().exec(s8);
            OutputStream outputstream = process.getOutputStream();
            outputstream.write(s9.getBytes());
            System.out.println(s8);
            System.out.println(s9);
            outputstream.close();
        } else
        {
            throw new Exception(" \356\305 \332\301\304\301\316\331 \301\304\322\305\323\301 \320\317\314\325\336\301\324\305\314\305\312 \323\317\317\302\333\305\316\311\321 ");
        }
    }

    private SQLRequest sql;
}
